package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.facade.TaxRetailerTaxService;
import com.irdstudio.efp.rule.service.dao.TaxRetailerTaxDao;
import com.irdstudio.efp.rule.service.domain.TaxRetailerTax;
import com.irdstudio.efp.rule.service.vo.TaxRetailerTaxVO;


/**
 * Service Impl: 个体户纳税信息表服务实现
 * @author ligm
 * @date 2019-04-29 
 */
@Service("taxRetailerTaxService")
public class TaxRetailerTaxServiceImpl implements TaxRetailerTaxService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxRetailerTaxServiceImpl.class);

	@Autowired
	private TaxRetailerTaxDao taxRetailerTaxDao;

   	/**
	 * 新增数据 
     * @param inTaxRetailerTaxVo
     * @return 
	 */
	public int insertTaxRetailerTax(TaxRetailerTaxVO inTaxRetailerTaxVo) {
		logger.debug("当前新增数据为:"+ inTaxRetailerTaxVo.toString());
		int num = 0;
		try {
			TaxRetailerTax taxRetailerTax = new TaxRetailerTax();
			beanCopy(inTaxRetailerTaxVo, taxRetailerTax);
			num = taxRetailerTaxDao.insertTaxRetailerTax(taxRetailerTax);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inTaxRetailerTaxVo
 	 * @return
	 */
	public int deleteByPk(TaxRetailerTaxVO inTaxRetailerTaxVo) {
		logger.debug("当前删除数据条件为:"+ inTaxRetailerTaxVo);
		int num = 0;
		try {
			TaxRetailerTax taxRetailerTax = new TaxRetailerTax();
			beanCopy(inTaxRetailerTaxVo, taxRetailerTax);
			num = taxRetailerTaxDao.deleteByPk(taxRetailerTax);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxRetailerTaxVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inTaxRetailerTaxVo
	 * @return 
	 */  
	public int updateByPk(TaxRetailerTaxVO inTaxRetailerTaxVo) {
		logger.debug("当前修改数据为:"+ inTaxRetailerTaxVo.toString());
		int num = 0;
		try {
			TaxRetailerTax taxRetailerTax = new TaxRetailerTax();
			beanCopy(inTaxRetailerTaxVo, taxRetailerTax);
			num = taxRetailerTaxDao.updateByPk(taxRetailerTax);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxRetailerTaxVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param taxRetailerTax
	 * @return 
	 */
	public TaxRetailerTaxVO queryByPk(TaxRetailerTaxVO inTaxRetailerTaxVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxRetailerTaxVo);
		try {
			TaxRetailerTax queryTaxRetailerTax = new TaxRetailerTax();
			beanCopy(inTaxRetailerTaxVo, queryTaxRetailerTax);
			TaxRetailerTax queryRslTaxRetailerTax = taxRetailerTaxDao.queryByPk(queryTaxRetailerTax);
			if (Objects.nonNull(queryRslTaxRetailerTax)) {
				TaxRetailerTaxVO outTaxRetailerTaxVo = beanCopy(queryRslTaxRetailerTax, new TaxRetailerTaxVO());
				logger.debug("当前查询结果为:"+ outTaxRetailerTaxVo.toString());
				return outTaxRetailerTaxVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param taxRetailerTax
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<TaxRetailerTaxVO> queryAllByLevelOne(TaxRetailerTaxVO taxRetailerTaxVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<TaxRetailerTaxVO> list = null;
		try {
			List<TaxRetailerTax> taxRetailerTaxs = taxRetailerTaxDao.queryAllByLevelOneByPage(taxRetailerTaxVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ taxRetailerTaxs.size());
			pageSet(taxRetailerTaxs, taxRetailerTaxVo);
			list = (List<TaxRetailerTaxVO>) beansCopy(taxRetailerTaxs, TaxRetailerTaxVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param taxRetailerTax
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerTaxVO> queryAllByLevelTwo(TaxRetailerTaxVO taxRetailerTaxVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<TaxRetailerTax> taxRetailerTaxs = taxRetailerTaxDao.queryAllByLevelTwoByPage(taxRetailerTaxVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+taxRetailerTaxs.size());
		List<TaxRetailerTaxVO> list = null;
		try {
			pageSet(taxRetailerTaxs, taxRetailerTaxVo);
			list = (List<TaxRetailerTaxVO>) beansCopy(taxRetailerTaxs, TaxRetailerTaxVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param taxRetailerTax
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerTaxVO> queryAllByLevelThree(TaxRetailerTaxVO taxRetailerTaxVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<TaxRetailerTax> taxRetailerTaxs = taxRetailerTaxDao.queryAllByLevelThreeByPage(taxRetailerTaxVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ taxRetailerTaxs.size());
		List<TaxRetailerTaxVO> list = null;
		try {
			pageSet(taxRetailerTaxs, taxRetailerTaxVo);
			list = (List<TaxRetailerTaxVO>) beansCopy(taxRetailerTaxs, TaxRetailerTaxVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param taxRetailerTax
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerTaxVO> queryAllByLevelFour(TaxRetailerTaxVO taxRetailerTaxVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxRetailerTax> taxRetailerTaxs = taxRetailerTaxDao.queryAllByLevelFourByPage(taxRetailerTaxVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxRetailerTaxs.size());
		List<TaxRetailerTaxVO> list = null;
		try {
			pageSet(taxRetailerTaxs, taxRetailerTaxVo);
			list = (List<TaxRetailerTaxVO>) beansCopy(taxRetailerTaxs, TaxRetailerTaxVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param taxRetailerTax
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerTaxVO> queryAllByLevelFive(TaxRetailerTaxVO taxRetailerTaxVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxRetailerTax> taxRetailerTaxs = taxRetailerTaxDao.queryAllByLevelFiveByPage(taxRetailerTaxVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxRetailerTaxs.size());
		List<TaxRetailerTaxVO> list = null;
		try {
			pageSet(taxRetailerTaxs, taxRetailerTaxVo);
			list = (List<TaxRetailerTaxVO>) beansCopy(taxRetailerTaxs, TaxRetailerTaxVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
}
